//
//  RootVCCell.m
//  高仿暴走斗图
//
//  Created by key on 16/3/29.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "RootVCCell.h"

@interface RootVCCell ()

@property (nonatomic, strong) UILabel *labelContent;

@end

@implementation RootVCCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.directionType = kSlideCellRevealDirectionTypeRight;
        [self addPanGestureRecognizerInView:self.contentView];
        
        CGFloat remain = 0.5f;
        HSYSlideView *slideView = [[HSYSlideView alloc] initWithFrame:CGRectMake(IPHONE_WIDTH - fabs(self.slidingWith), remain, fabs(self.slidingWith), self.contentView.viewHeight - remain*2)];
        
        @weakify(self);
        slideView.didSelectDelete = ^(kSelectType type) {
         
            @strongify(self);
            if (self.delegate && [self.delegate respondsToSelector:@selector(sendSelectDeleteForCell:)] && type == kSelectTypeDelete) {
                
                [self.delegate sendSelectDeleteForCell:self];
            } else if (self.delegate && [self.delegate respondsToSelector:@selector(sendSelectCancel)] && type == kSelectTypeCancel) {
                
                [self.delegate sendSelectCancel];
            }
        };
        [self insertSubview:slideView belowSubview:self.contentView];
        
        self.labelContent = [NSObject createAdaptiveLabelWithText:nil
                                                        textColor:[UIColor blackColor]
                                                          bkColor:CLEAR_COLOR
                                                             font:HSYFONTBLODSIZE(15)
                                          preferredMaxLayoutWidth:(IPHONE_WIDTH - 20)
                                                    textAlignment:NSTextAlignmentLeft];
        [self.contentView addSubview:self.labelContent];
        [self.labelContent mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(10);
            make.top.equalTo(self.contentView.mas_top).offset(10);
            make.width.equalTo(@(IPHONE_WIDTH - 20));
        }];
        
    }
    return self;
}

- (void)setConstraint:(NSString *)constraint
{
    _constraint = constraint;
    self.labelContent.text = constraint;
    [self updateConstraint];
}

- (void)updateConstraints
{
    [self updateConstraintsForLastView:self.labelContent asOffset:10.0f];
    [super updateConstraints];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
